/*
	This script file is part of the Sonic 3 A.I.R. script software distribution.
	Copyright (C) 2017-2024 by Eukaryot

	Published under the GNU GPLv3 open source software license, see license.txt
	or https://www.gnu.org/licenses/gpl-3.0.en.html
*/



//-------------------------------------------------------//
// General camera update                                 //
//-------------------------------------------------------//

//# address-hook(0x01c38a) end(0x01c3f4)
function void UpdateCameraBoundsInLevel()
{
	u8 offset = global.zone * 4 + global.act * 2

	// Targets:
	//  - 0x01c456	-> offset = 0x00		-> AIZ 1
	//  - 0x01c622	-> offset = 0x02		-> AIZ 2
	//  - 0x01c87e	-> offset = 0x04		-> HCZ 1
	//  - 0x01c8f6	-> offset = 0x06		-> HCZ 2
	//  - 0x01c91c	-> offset = 0x08		-> MGZ 1
	//  - 0x01c91c	-> offset = 0x0a		-> MGZ 2
	//  - 0x01c9ca	-> offset = 0x0c		-> CNZ 1
	//  - 0x01c9ca	-> offset = 0x0e		-> CNZ 2
	//  - 0x01c9ca	-> offset = 0x10		-> FBZ 1
	//  - 0x01c9ca	-> offset = 0x12		-> FBZ 1
	//  - 0x01c9cc	-> offset = 0x14		-> ICZ 1
	//  - 0x01ca0e	-> offset = 0x16		-> ICZ 2
	//  - 0x01ca3e	-> offset = 0x18		-> LBZ 1
	//  - 0x01ca40	-> offset = 0x1a		-> LBZ 2
	//  - 0x01caac	-> offset = 0x1c		-> MHZ 1	 (empty function)
	//  - 0x01caac	-> offset = 0x1e		-> MHZ 2	 (empty function)
	//  - 0x01caac	-> offset = 0x20		-> SOZ 1	 (empty function)
	//  - 0x01caac	-> offset = 0x22		-> SOZ 2	 (empty function)
	//  - 0x01caac	-> offset = 0x24		-> LRZ 1	 (empty function)
	//  - 0x01caac	-> offset = 0x26		-> LRZ 2	 (empty function)
	//  - 0x01caac	-> offset = 0x28		-> SSZ S/T	 (empty function)
	//  - 0x01caac	-> offset = 0x2a		-> SSZ Knux	 (empty function)
	//  - 0x01caac	-> offset = 0x2c		-> DEZ 1	 (empty function)
	//  - 0x01caac	-> offset = 0x2e		-> DEZ 2	 (empty function)
	//  - 0x01caac	-> offset = 0x30, 0x32	-> DDZ		 (empty function)
	//  - 0x01caac	-> offset = 0x34, 0x36	-> Outro S/T (empty function)
	//  - 0x01caac	-> offset = 0x38, 0x3a	-> ALZ		 (empty function)
	//  - 0x01caac	-> offset = 0x3c, 0x3e	-> BPZ		 (empty function)
	//  - 0x01caac	-> offset = 0x40, 0x42	-> DPZ		 (empty function)
	//  - 0x01caac	-> offset = 0x44, 0x46	-> CGZ		 (empty function)
	//  - 0x01caac	-> offset = 0x48, 0x4a	-> EMZ		 (empty function)
	//  - 0x01caac	-> offset = 0x4c, 0x4e	-> Bonus GM	 (empty function)
	//  - 0x01caac	-> offset = 0x50, 0x52	-> Bonus GS	 (empty function)
	//  - 0x01caac	-> offset = 0x54, 0x56	-> Bonus SM	 (empty function)
	//  - 0x01caac	-> offset = 0x58		-> LRZ Boss	 (empty function)
	//  - 0x01caac	-> offset = 0x5a		-> HPZ		 (empty function)
	//  - 0x01caac	-> offset = 0x5c		-> DEZ Boss	 (empty function)
	//  - 0x01caac	-> offset = 0x5e		-> HPZ Cave	 (empty function)
	call tableLookupAddress(0x01c3f6, offset)

	D1 = 2
	D0.s16 = move_area.bottom.target - move_area.bottom.current
	if (D0.s16 != 0)
	{
		if (D0.s16 > 0)
		{
			D0.u16 = camera.position.y.u16 + 8
			if (D0.u16 >= move_area.bottom.current && (u8[0xffffb000 + 0x2a] & char.flag.IN_AIR))
			{
				D1.u16 *= 4
			}
		}
		else
		{
			D1.s16 = -D1.s16
			D0.u16 = camera.position.y.u16
			if (D0.u16 > move_area.bottom.target)
			{
				move_area.bottom.current = D0.u16 & 0xfffe
			}
		}

		move_area.bottom.current += D1.u16
		u8[0xffffee32] = 1
	}
}


//# address-hook(0x01caac) end(0x01caac)
function void UpdateCameraBounds.Empty()
{
}
